
app.controller('marketCtrl',['$routeParams','$scope','$http','goods','cart',function($routeParams,$scope,$http,goods,cart){
	$scope.list = ['热销榜','优选水果','天天特价','牛奶面包','热销榜','天天特价','牛奶面包','优选水果','热销榜','天天特价','牛奶面包','优选水果','热销榜','天天特价','牛奶面包','优选水果']
	//$scope.listData = [];
	console.log(goods);
	$scope.goods = goods;
	$scope.text = $routeParams.text || '热销榜';
	console.log($scope.goods);
	$scope.num = 0;
	function request(text){
		if(!$scope.goods[$scope.text]){
			
			$http.get('http://h5.yztctech.net/api/axf/apicategory.php?category='+$scope.text)
			.success(function(req){
				$scope.goods[$scope.text] = req.data;
			})
		}
			
	}
	
	request();
	$scope.getData = function(text,index){
		$scope.num = index;
		$scope.text = text;
		request();
	};
	$scope.addNum = function(num,item){
//		console.log(obj)
		if(item.num === undefined){
			item.num = 1;
		}else{
			item.num += num;
		}
		
		if(item.num>0){
			cart.addCart($scope.text+item.id,item);
		}else{
			cart.dele($scope.text+item.id,item);
		}
	}
	
}])